﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Util.Setvices.Model;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace Util.Setvices.Controllers
{
    [Route("[controller]")]
    public class SchoolController : Controller
    {
        private IFreeSql _fsql;
        public SchoolController(IFreeSql fsql)
        {
            _fsql = fsql;
        }

        [HttpGet]
        public object lg_getSchoolWithValue(string value)
        {

            if (string.IsNullOrEmpty(value))
            {
                return new List<School>();
            }

            var list = _fsql.Select<School>()
                .Where(a => a.school_name.Contains(value) || a.province_name.Contains(value)
                || a.city_name.Contains(value))
                .Page(1, 10)
                .ToList(a => new
                {
                    id = a.school_id,
                    name = a.school_name
                });

            return list;
        }
    }
}
